﻿using UnityEngine;
using System.Collections;

public class Bullet : MonoBehaviour {

    public float speed = 20;
    public float attack;

	// Use this for initialization
	void Start () {

        Destroy(gameObject, 2);
	}
	
	// Update is called once per frame
	void Update () {

        // transform.forword移动方向是世界坐标系的z轴移动
        // transform.forword为正时，朝向Z轴的负方向，为负时,朝向Z轴的正方向
        // Vector3.forword移动方向是自身坐标系的Z轴移动
        transform.Translate(Vector3.forward* speed *Time.deltaTime);
	}

    // 进行子弹的触发检测
    void OnTriggerEnter(Collider other)
    {
        if (other.tag.CompareTo(Tags.boss)==0 || other.tag.CompareTo(Tags.monst)==0)
        {
            other.GetComponent<AttackAndDamage>().TakenDamage(attack);
            Destroy(gameObject);
        }
    }
}
